home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 September
/
PCWorld_2008-09_cd.bin
/
v cisle
/
sadanastroju
/
cacheviewer-0.4.7.1-fx.xpi
/
chrome
/
cacheviewer.jar
/
content
/
cacheviewer
/
rdf.js
< prev
next >
Wrap
Text File
|
2008-03-03
|
7KB
|
214 lines
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents (ry
*
* inspired by bbs2chreader
*
* ***** END LICENSE BLOCK *****
*/
function RDF() {
this._ds = Cc["@mozilla.org/rdf/datasource;1?name=in-memory-datasource"]
.createInstance(Ci.nsIRDFDataSource);
}
RDF.prototype = {
get NS_CACHEVIEWER() {
return "http://park2.wakwak.com/~benki/cacheviewer#";
},
get RDF_ITEM_ROOT() {
return "urn:cache:item:root";
},
get RDF_ITEM_SEARCH() {
return "urn:cache:item:search";
},
get datasource() {
return this._ds;
},
get rdfService() {
if ( !this._rdfService ) {
this._rdfService = Cc['@mozilla.org/rdf/rdf-service;1']
.getService(Ci.nsIRDFService);
}
return this._rdfService;
},
_rdfService: null,
get rdfContainerUtils() {
if ( !this._rdfContainerUtils ) {
this._rdfContainerUtils = Cc['@mozilla.org/rdf/container-utils;1']
.getService(Ci.nsIRDFContainerUtils);
}
return this._rdfContainerUtils;
},
_rdfContainerUtils: null,
getResource: function(aResourceID) {
return this.rdfService.GetResource(aResourceID);
},
getLiteral: function(aValue) {
return this.rdfService.GetLiteral(aValue);
},
getIntLiteral: function(aValue) {
return this.rdfService.GetIntLiteral(aValue);
},
getDateLiteral: function(aValue) {
return this.rdfService.GetDateLiteral(aValue);
},
setLiteralProperty: function(aResourceOrID, aProperty, aValue) {
var source = (typeof(aResourceOrID)=="string") ?
this.getResource(aResourceOrID) : aResourceOrID;
var property = this.getResource(aProperty);
var value = this.getLiteral(aValue);
this._ds.Assert(source, property, value, true);
},
getLiteralProperty: function(aResourceOrID, aProperty) {
var source = (typeof(aResourceOrID)=="string") ?
this.getResource(aResourceOrID) : aResourceOrID;
var target = this._ds.GetTarget(source, this.getResource(aProperty), true);
if (target) return target.QueryInterface(Ci.nsIRDFLiteral).Value;
return null;
},
setIntProperty: function(aResourceOrID, aProperty, aValue) {
var source = (typeof(aResourceOrID)=="string") ?
this.getResource(aResourceOrID) : aResourceOrID;
var property = this.getResource(aProperty);
var value = this.getIntLiteral(aValue);
this._ds.Assert(source, property, value, true);
},
getIntProperty: function(aResourceOrID, aProperty) {
var source = (typeof(aResourceOrID)=="string") ?
this.getResource(aResourceOrID) : aResourceOrID;
var target = this._ds.GetTarget(source, this.getResource(aProperty), true);
if (target) return target.QueryInterface(Ci.nsIRDFInt).Value;
return null;
},
setDateProperty: function(aResourceOrID, aProperty, aValue) {
var source = (typeof(aResourceOrID)=="string") ?
this.GetResource(aResourceOrID) : aResourceOrID;
var property = this.getResource(aProperty);
var value = this.getDateLiteral(aValue);
this._ds.Assert(source, property, value, true);
},
getDateProperty: function(aResourceOrID, aProperty) {
var source = (typeof(aResourceOrID)=="string") ?
this.getResource(aResourceOrID) : aResourceOrID;
var target = this._ds.GetTarget(source, this.getResource(aProperty), true);
if (target) return target.QueryInterface(Ci.nsIRDFDate).Value;
return null;
},
appendResource: function(aResourceOrID, aParentContainerOrID) {
var resource = this.getResource(aResourceOrID);
if (aParentContainerOrID) {
var parentContainer = (typeof(parentContainer)=="string") ?
this.getContainer(aParentContainerOrID) : aParentContainerOrID;
parentContainer.AppendElement(resource);
}
return resource;
},
removeResource: function(aResourceOrID, aParentContainerOrID) {
var resource = (typeof(aResourceOrID)=="string") ?
this.getResource(aResourceOrID) : aResourceOrID;
// 親コンテナからリソースを削除
if (aParentContainerOrID) {
var parentContainer = (typeof(aParentContainerOrID)=="string") ?
this.getContainer(aParentContainerOrID) : aParentContainerOrID;
parentContainer.RemoveElement(resource, true);
}
// リソースを削除
var names = this._ds.ArcLabelsOut(resource);
var name, value;
while (names.hasMoreElements()) {
name = names.getNext().QueryInterface(Ci.nsIRDFResource);
value = this._ds.GetTarget(resource, name, true);
this._ds.Unassert(resource, name, value);
}
},
makeSeqContainer: function(aResourceID) {
var containerRes = this.getResource(aResourceID);
return this.rdfContainerUtils.MakeSeq(this._ds, containerRes);
},
getContainer: function(aResourceID) {
try {
var containerRes = this.getResource(aResourceID);
var rdfContainer = Cc["@mozilla.org/rdf/container;1"]
.createInstance(Ci.nsIRDFContainer);
rdfContainer.Init(this._ds, containerRes);
return rdfContainer;
} catch(ex) {}
return this.makeSeqContainer(aResourceID);
},
clearContainer: function(aResourceID) {
var container = this.getContainer(aResourceID);
while (container.GetCount()) {
container.RemoveElementAt(1, true);
}
},
search: function(aSearchString){
this.clearContainer(this.RDF_ITEM_SEARCH);
var searchContainer = this.getContainer(this.RDF_ITEM_SEARCH);
var list = aSearchString.toUpperCase().replace(/ +/g, " ").replace(/ $/, "").split(" ");
function checkKey(aKey, aList) {
var length = aList.length;
var rv = true;
for (var i=0; i<length; i++) {
rv = rv && ( ( aKey.toUpperCase().indexOf(aList[i]) > -1 ) ? true : false );
if (!rv) break;
}
return rv;
}
var resources = this._ds.GetAllResources();
var timer = Components.classes["@mozilla.org/timer;1"]
.createInstance(Components.interfaces.nsITimer);
var self = this;
function timerCallback() {}
timerCallback.prototype = {
observe: function(aTimer, aTopic, aData) {
var i = 0;
while (resources.hasMoreElements() && i<100) {
var resource = resources.getNext().QueryInterface(Ci.nsIRDFResource);
var key = self.getLiteralProperty(resource, self.NS_CACHEVIEWER + "key");
if (key && checkKey(key, list))
searchContainer.AppendElement(resource);
i++;
}
if (resources.hasMoreElements())
timer.init(new timerCallback(), 0, timer.TYPE_ONE_SHOT);
}
}
timer.init(new timerCallback(), 0, timer.TYPE_ONE_SHOT);
}
};